package zzuli.edu.cn.controller;

import io.swagger.annotations.*;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

@Api(value = "@ApiImplicitParam注解测试", tags = "@ApiImplicitParam注解测试")
@RestController
public class Swagger2Controller3 {

    /**
     * @ApiImplicitParam 注解用在方法上，用于对方法的参数进行说明描述
     * name: 参数名称
     * value:参数描述
     * required: 参数是否必须
     * paramType:参数类型 query body
     * dataType: 数据类型
     */
    @ApiOperation(value = "@ApiImplicitParam测试", notes = "此方法用于@ApiImplicitParam测试")
    @PostMapping("/apiImplicitParam")
    @ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "query", dataType = "String")
    public String ApiImplicitParamTest(String username) {
        return username;
    }

    /**
     * @ApiImplicitParam 注解用在方法上，用于对方法的参数进行说明描述
     * 它的作用和 @ApiPara 注解一样，两者的区别在于 @ApiImplicitParam 用在方法上，@ApiParam 用在方法的参数上
     *
     * 注意:@ApiParam 和 @ApiImplicitParam 注解同时使用，且属性name值都与参数名称一致时，@ApiImplicitParam有效，@ApiParam无效
     * (即使@ApiParam 注解和 @RequestParam注解一起使用时也是如此)
     */
    @ApiOperation(value = "@ApiImplicitParam测试2", notes = "此方法用于@ApiImplicitParam测试")
    @PostMapping("/apiImplicitParam2")
    @ApiImplicitParam(name = "username", value = "用户名(username)", required = true, paramType = "query", dataType = "String")
    public String ApiImplicitParamTest2(@ApiParam(name = "username", value= "用户名", required = true) @RequestParam String username) {
        return username;
    }

    /**
     * @ApiImplicitParams 注解用在方法上，用于对方法的多个参数进行说明描述
     */
    @ApiOperation(value = "@ApiImplicitParams", notes = "此方法用于@ApiImplicitParams测试")
    @PostMapping("/apiImplicitParams")
    @ApiImplicitParams( value = {
            @ApiImplicitParam(name = "username", value = "用户名", required = true, paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "password", value = "密码",   required = true, paramType = "query", dataType = "String")
    })
    public String ApiImplicitParamTest3(String username, String password) {
        return username + password;
    }

}
